import { NamespaceCodeEnum } from '/@/enums/iamEnum'
import { removeRepeatSlashOfUrl } from '/@/utils/index'
import { WorkspaceTypeEnum } from "/@/enums/iamEnum"
import { useIam } from '/@/hooks/web/useIam'

export const getBizUrl = (params, url) => {
  let sysType = ''
  const workspaceType = useIam().getWorkspaceType()
  const namespaceCode = params.apiNamespaceCode || params.namespaceCode

  const isManage = workspaceType == WorkspaceTypeEnum.APP_MGT || workspaceType == WorkspaceTypeEnum.APP_GOVERN_HUB
  console.log('workspaceType', workspaceType, 'isManage', isManage, 'namespaceCode', namespaceCode)
  if (isManage) {
    if (namespaceCode == NamespaceCodeEnum.APP_MGT) {
      sysType = 'manage'
    } else if (namespaceCode == NamespaceCodeEnum.APP_GOVERN_HUB) {
      sysType = 'system'
    } else {
      sysType = 'system'
    }
    delete params.apiNamespaceCode
    return removeRepeatSlashOfUrl(url.replace('%s', `/${sysType}/`))
  } else {
    return removeRepeatSlashOfUrl(url.replace('%s', `/`))
  }
}
